package cn.iocoder.yudao.module.crm.dal.mysql.cluetransrule;

import java.time.LocalDateTime;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.crm.dal.dataobject.cluetransrule.ClueTransRuleDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.crm.controller.admin.cluetransrule.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 转化规则 Mapper
 *
 * @author 数创万维
 */
@Mapper
public interface ClueTransRuleMapper extends BaseMapperX<ClueTransRuleDO> {

    default PageResult<ClueTransRuleDO> selectPage(ClueTransRulePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ClueTransRuleDO>()
                .eqIfPresent(ClueTransRuleDO::getAccountId, reqVO.getAccountId())
                .eqIfPresent(ClueTransRuleDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ClueTransRuleDO::getMinInterval, reqVO.getMinInterval())
                .eqIfPresent(ClueTransRuleDO::getTransPos, reqVO.getTransPos())
                .eqIfPresent(ClueTransRuleDO::getModuleId, reqVO.getModuleId())
                .betweenIfPresent(ClueTransRuleDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ClueTransRuleDO::getId));
    }

    @Select("SELECT * from crm_clue_trans_rule where status = 1 and next_query_time <= #{nextTime} order by id asc")
    List<ClueTransRuleDO> getExecutableList(LocalDateTime nextTime);

}